package IO流;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class Test7 {
    public static void main(String[] args) {
        //BufferedInputStream 和 BufferedOutputStream 这两个流是缓冲字节流
        FileInputStream fis=null;
        FileOutputStream fos=null;
        BufferedInputStream bis=null;
        BufferedOutputStream bos=null;
        try {
            fis=new FileInputStream("e:/yk.jpg");
            bis=new BufferedInputStream(fis);//流的嵌套
           // bis=new BufferedInputStream(new FileInputStream("")); 两行代码合成一行
            fos=new FileOutputStream("e:/mei.jpg");
            bos=new BufferedOutputStream(fos);//流的嵌套
            //bos=new BufferedOutputStream(new FileOutputStream(""));两行代码合成一行
            int temp=0;
            //缓冲流中byte数组长度默认是8192
            while((temp=bis.read())!=-1){
                bos.write(temp);
            }
            bos.flush();

        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try{
                //注意关闭的顺序 后开的先关闭
                if(bis!=null)bis.close();;
                if(fis!=null)fis.close();
                if(bos!=null)bos.close();
                if(fos!=null)fos.close();

            }catch (Exception e){
               e.printStackTrace();
            }
        }
    }
}
